
package com.weiqiao.mall.repository.impl;

import com.mongodb.client.MongoCollection;
import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import com.weiqiao.mall.repository.IShelfRepository;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 订单后台配置 持久化层 实现层 继承IShelfDao
 *
 * @author tiyer
 */
@Repository("ShelfRepositoryImpl")
public class ShelfRepositoryImpl extends BaseMongoDaoImpl implements IShelfRepository {

    private String collectionName = "shelf";


    @Override
    public List<String> getShelfs(Bson filter) {
        return this.findFilter(collectionName, filter);
    }

    @Override
    public boolean updateShelf(Bson filter, String json) {

        return this.updateReplace(collectionName, filter, json);
    }

    @Override
    public List<String> getShelftsByFilterSortSkipLimt(int company_id, Bson bson, Bson sort, int skip, int pageSize) {

        return this.findFilterSortSkipLimit(collectionName, bson, sort, skip, pageSize);
    }

    @Override
    public int countByBson(Bson bson) {

        MongoCollection<Document> dbCollection = getCollection(collectionName);
        return (int) dbCollection.count(bson);
    }

    @Override
    public boolean deleteById(Bson filter) {
        return this.deleteOne(collectionName, filter);
    }

    @Override
    public List<String> getListByFilterSort(Bson filter, Bson sort) {

        List<String> result = this.findFilterSort(collectionName, filter, sort);
        return result;
    }

    @Override
    public String getOneByFilter(Bson filter) {

        String result = this.findOne(collectionName, filter);
        return result;
    }

    @Override
    public boolean updateShelfById(Bson filter, Document doc, boolean bool) {
        return this.updateOne(collectionName, filter, doc, false);
    }

}
